package com.rjpacket.supernews.app.tasks;

/**
 * Created by aaa on 15-3-10.
 */

import android.content.Context;
import android.os.AsyncTask;
import com.rjpacket.supernews.app.Constants;
import com.rjpacket.supernews.app.utils.HttpTool;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 获得Recommend频道一次刷新的News总数以及item需要的新闻简介信息。不包含内容。
 */
public class RecommendNewsTask extends AsyncTask<String, Integer, String> {
    private TaskCallOnBack back;

    public RecommendNewsTask(TaskCallOnBack back) {
        this.back = back;
    }

    @Override
    protected String doInBackground(String... params) {
        String ret = null;
        if (params != null && params.length > 4) {
            String count = params[0];
            String pullType = params[1];
            String stime = params[2];
            String channel = params[3];
            String sequence = params[4];
            String uid = "";
            if (params.length > 5) {
                uid = params[5];
            }

            String url = Constants.APP_NEWS_API + "moreNews2.m?count=" + count + "&vcode=16299&pull_type=" + pullType + "&width=480&udid=073CC368CD437982D321EE88ED3EB3AF&stime=" + stime + "&terminal=android&cpid=bnf1377_10890_001&uid=" + uid + "&client=newsapp&channel=" + channel + "&sequence=" + sequence;

            byte[] bytes = HttpTool.get(url);

            if (bytes != null) {
                String str = new String(bytes);

                try {
                    ret = str;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

        return ret;
    }

    @Override
    protected void onPostExecute(String jsonObject) {
        if (jsonObject != null) {
            back.callOnBack(jsonObject);
        } else {
            back.callOnBack(null);
        }
    }
}
